package cc.laop.java.concurrent;

import java.util.Date;
import java.util.concurrent.Semaphore;

/**
 * @Auther: Pengpeng
 * @Date: create in 2018/1/9 19:30
 * @Description:
 */
public class SemaphoreTest {

    public static void main(String[] args) {

        Semaphore sph = new Semaphore(5);

        for (int i = 0; i < 7; i++) {
            new Thread(() -> {
                try {
                    sph.acquire();
                    System.out.println(Thread.currentThread() + " --- " + new Date());
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } finally {
                    sph.release();
                }
            }).start();
        }

    }

}
